package com.FindImportKeys.Fram;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
/**
 * @author cc
 * @date 2021/8/5 15:09
 * @Description
 */

public class BrowseAction implements ActionListener{


        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getSource().equals(MainForm.buttonBrowseSource)) {
                JFileChooser fcDlg = new JFileChooser();
                fcDlg.setDialogTitle("请选择文档文件夹...");

//                FileNameExtensionFilter filter = new FileNameExtensionFilter(
//                        "文本文件(*.txt;*.kcd)", "txt", "kcd");
                fcDlg.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

                int returnVal = fcDlg.showOpenDialog(null);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    String filepath = fcDlg.getSelectedFile().getPath();
                    MainForm.sourcefile.setText(filepath);
                }
            } else if (e.getSource().equals(MainForm.buttonBrowseTarget)) {
                JFileChooser fcDlg = new JFileChooser();
                fcDlg.setDialogTitle("请选择加密或解密后的文件存放目录");

                fcDlg.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                int returnVal = fcDlg.showOpenDialog(null);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    String filepath = fcDlg.getSelectedFile().getPath();
                    MainForm.targetfile.setText(filepath);
                }
            }
        }
}
